import warnings
warnings.filterwarnings("ignore")
import numpy as np
from time import *
from pandas import read_excel
from pandas import DataFrame
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
from xgboost import plot_importance
from xgboost import XGBRegressor

def splitDataSet(dataset, randomIndex):
    trainSet = []
    testSet = []
    for i in range(len(dataset)):
        if i in randomIndex:
            testSet.append(dataset[i])
        else:
            trainSet.append(dataset[i])
    trainSet = np.array(trainSet)
    testSet = np.array(testSet)
    return trainSet, testSet

randomIndex = (5, 14, 22, 30, 37, 43, 60, 72, 75, 77, 96, 107, 120, 123, 164, 166, 172, 183, 194, 214, 216, 219, 229, 234, 265, 276, 279, 300, 310, 343, 353, 356, 358, 360, 367, 369, 380, 387, 388, 391, 400, 442, 453, 456, 469, 470, 484, 511, 523, 524, 531, 532, 534, 561, 570, 572, 574, 588, 610, 615, 618, 632, 651, 659, 661, 674, 681, 682, 688, 697, 704, 711, 718, 720, 745, 766, 783, 794, 796, 800, 801, 805, 820, 832, 834, 841, 845, 852, 860, 899, 901, 911, 915, 917, 924, 930, 935, 943, 954, 955, 965, 978, 1032, 1046, 1058, 1062, 1063, 1077, 1115, 1123, 1166, 1190, 1196, 1201, 1213, 1224, 1235, 1238, 1255, 1277, 1294, 1301, 1311, 1316, 1323, 1328, 1368, 1370, 1375, 1388, 1401, 1411, 1423, 1445, 1496, 1498, 1510, 1512, 1517, 1519, 1532, 1557, 1562, 1595, 1603, 1604, 1606, 1615, 1622, 1654, 1662, 1675, 1685, 1692, 1693, 1695, 1698, 1699, 1712, 1716, 1717, 1726, 1728, 1737, 1738, 1740, 1747, 1755, 1756, 1761, 1763, 1765, 1771, 1779, 1780, 1790, 1795, 1807, 1815, 1818, 1819, 1825, 1834, 1855, 1878, 1880, 1897, 1898, 1903, 1922, 1940, 1942, 1948, 1977, 1979, 1981, 2000, 2003, 2011, 2048, 2049, 2057, 2077, 2078, 2092, 2100, 2109, 2120, 2154, 2165, 2168, 2183, 2197, 2198, 2207, 2223, 2238, 2250, 2254, 2257, 2269, 2274, 2275, 2300, 2309, 2315, 2321, 2342, 2352, 2363, 2365, 2375, 2384, 2389, 2398, 2423, 2425, 2433, 2453, 2455, 2457, 2465, 2474, 2483, 2485, 2486, 2487, 2499, 2506, 2513, 2551, 2576, 2583, 2597, 2608, 2615, 2630, 2631, 2634, 2647, 2689, 2694, 2713, 2723, 2725, 2734, 2735, 2744, 2748, 2753, 2758, 2782, 2807, 2849, 2865, 2869, 2876, 2892, 2897, 2907, 2909, 2926, 2927, 2956, 2967, 2978, 2998, 3000, 3003, 3026, 3027, 3048, 3059, 3078, 3085, 3089, 3111, 3120, 3125, 3139, 3147, 3152, 3160, 3179, 3196, 3207, 3208, 3226, 3228, 3245, 3254, 3263, 3277, 3279, 3287, 3301, 3305, 3309, 3317, 3318, 3323, 3336, 3343, 3351, 3360, 3361, 3386, 3407, 3428, 3431, 3432, 3443, 3457, 3461, 3462, 3470, 3472, 3474, 3492, 3498, 3512, 3537, 3554, 3587, 3596, 3630, 3639, 3648, 3672, 3676, 3677, 3686, 3688, 3711, 3712, 3722, 3735, 3739, 3740, 3745, 3746, 3752, 3755, 3758, 3786, 3791, 3804, 3812, 3814, 3817, 3834, 3843, 3860, 3865, 3891, 3892, 3908, 3926, 3938, 3939, 3948, 3953, 3975, 3976, 3983, 3990, 4014, 4050, 4063, 4072, 4075, 4081, 4083, 4089, 4092, 4106, 4110, 4111, 4114, 4116, 4119, 4123, 4136, 4155, 4180, 4184, 4185, 4190, 4206, 4217, 4221, 4230, 4232, 4234, 4237, 4247, 4268, 4271, 4276, 4296, 4301, 4305, 4309, 4332, 4336, 4343, 4350, 4358, 4365, 4368, 4369, 4371, 4377, 4380, 4381, 4417, 4427, 4431, 4438, 4440, 4445, 4474, 4485, 4509, 4522, 4525, 4529, 4534, 4536, 4540, 4548, 4552, 4567, 4575, 4583, 4603, 4607, 4611, 4622, 4629, 4643, 4660, 4673, 4679, 4706, 4707, 4714, 4737, 4738, 4753, 4756, 4782, 4785, 4801, 4816, 4819, 4832, 4843, 4860, 4877, 4901, 4910, 4922, 4923, 4926, 4928, 4939, 4941, 4942, 4946, 4957, 4973, 5011, 5014, 5015, 5024, 5029, 5046, 5061, 5095, 5120, 5125, 5126, 5132, 5145, 5158, 5161, 5169, 5188, 5202, 5205, 5207, 5215, 5221, 5233, 5236, 5287, 5292, 5293, 5321, 5330, 5331, 5343, 5346, 5348, 5352, 5393, 5398, 5400, 5405, 5419, 5430, 5432, 5436, 5437, 5440, 5441, 5451, 5461, 5463, 5468, 5498, 5501, 5503, 5508, 5509, 5566, 5574, 5575, 5577, 5609, 5617, 5655, 5658, 5693, 5719, 5721, 5725, 5732, 5735, 5737, 5740, 5746, 5750, 5772, 5774, 5790, 5796, 5800, 5807, 5835, 5848, 5849, 5857, 5866, 5871, 5888, 5919, 5926, 5952, 5957, 5963, 5977, 5984, 5987, 5991, 6003, 6014, 6017, 6044, 6053, 6056, 6069, 6078, 6092, 6106, 6128, 6132, 6141, 6169, 6172, 6197, 6199, 6206, 6217, 6220, 6228, 6243, 6256, 6258, 6277, 6280, 6285, 6288, 6314, 6318, 6328, 6334, 6346, 6349, 6355, 6357, 6371, 6378, 6388, 6389, 6395, 6400, 6416, 6447, 6461, 6467, 6502, 6504, 6516, 6558, 6568, 6569, 6574, 6583, 6593, 6596, 6608, 6609, 6623, 6625, 6635, 6646, 6656, 6665, 6673, 6675, 6688, 6721, 6735, 6740, 6768, 6770, 6773, 6780, 6789, 6800, 6803, 6806, 6810, 6813, 6818, 6840, 6842, 6847, 6849, 6853, 6865, 6897, 6904, 6918, 6922, 6935, 6945, 6952, 6962, 6981, 6991, 6996, 7003, 7017, 7021, 7031, 7036, 7039, 7048, 7051, 7052, 7057, 7070, 7071, 7084, 7090, 7120, 7129, 7136, 7142, 7143, 7150, 7158, 7172, 7175, 7179, 7191, 7200, 7204, 7224, 7229, 7230, 7231, 7251, 7256, 7261, 7262, 7271, 7287, 7295, 7310, 7311, 7337, 7338, 7341, 7342, 7371, 7415, 7422, 7433, 7436, 7441, 7458, 7471, 7473, 7474, 7488, 7505, 7511, 7515, 7545, 7551, 7553, 7568, 7576, 7582, 7583, 7584, 7598, 7617, 7626, 7632, 7640, 7673, 7688, 7699, 7726, 7743, 7746, 7766, 7771, 7777, 7810, 7821, 7822, 7832, 7836, 7850, 7857, 7864, 7869, 7876, 7891, 7894, 7903, 7911, 7913, 7914, 7924, 7957, 7967, 7974, 7978, 7992, 7994, 7996, 7999, 8000, 8001, 8013, 8037, 8042, 8044, 8045, 8047, 8052, 8060, 8076, 8092, 8093, 8110, 8143, 8160, 8168, 8170, 8171, 8204, 8212, 8218, 8223, 8234, 8237, 8249, 8250, 8251, 8254, 8265, 8266, 8268, 8278, 8283, 8296, 8298, 8301, 8302, 8335, 8349, 8355, 8373, 8395, 8413, 8416, 8434, 8436, 8441, 8448, 8452, 8460, 8464, 8475, 8479, 8482, 8492, 8500, 8517, 8518, 8519, 8524, 8528, 8530, 8533, 8538, 8544, 8558, 8559, 8565, 8571, 8603, 8615, 8623, 8629, 8639, 8645, 8662, 8670, 8680, 8686, 8693, 8711, 8717, 8726, 8732, 8741, 8753, 8757, 8770, 8775, 8779, 8816, 8833, 8870, 8875, 8885, 8892, 8902, 8913, 8914, 8922, 8931, 8939, 8940, 8970, 8971, 8978, 8979, 8984, 8995, 9017, 9018, 9019, 9024, 9039, 9051, 9056, 9073, 9076, 9095, 9097, 9098, 9099, 9103, 9107, 9120, 9123, 9124, 9125, 9141, 9163, 9164, 9167, 9173, 9190, 9212, 9245, 9256, 9263, 9291, 9311, 9322, 9325, 9328, 9333, 9337, 9341, 9352, 9368, 9380, 9414, 9417, 9419, 9437, 9440, 9443, 9459, 9461, 9470, 9475, 9481, 9482, 9510, 9530, 9533, 9542, 9543, 9549, 9554, 9567, 9580, 9585, 9586, 9600, 9603, 9613, 9622, 9626, 9633, 9642, 9656, 9669, 9670, 9678, 9679, 9683, 9705, 9710, 9732, 9748, 9755, 9791, 9802, 9817, 9824, 9833, 9836, 9844, 9860, 9866, 9875, 9879, 9881, 9890, 9894, 9914, 9940, 9968, 9981, 9988, 9994)

df = read_excel(r'C:\Users\zll\Desktop\JMS_\RawData.xlsx',Sheetname='Sheet1',header=0 )
len1 = df['Case ID'].__len__()
eventA = df.ix[:,[ 'Register_Request',  'Reason1', 'Resource1']].values  #1, 3, 1   5
eventB = df.ix[:,[ 'Date_Check', 'Type2', 'Resource2',]].values #1, 2, 1   9
eventC = df.ix[:,[ 'Mode_Audit', 'Resource3']].values  #1,  1   11
eventD = df.ix[:,[ 'Manual_Review',  'Resource4']].values  #2,  2   15
eventE = df.ix[:,[ 'Reason_Review', 'Result5', 'Resource5']].values #2, 3, 2   22
eventH = df.ix[:,[ 'Ticket_Check', 'Valid6', 'Resource6']].values # 2, 3, 2   29
eventF = df.ix[:,[ 'Casually_Examine', 'Result7', 'Resource7']].values  # 2, 3, 2   36
eventG = df.ix[:,[ 'Thoroughly_Examine', 'Result8', 'Resource8']].values # 2, 3, 2   43
eventI = df.ix[:,[ 'Decide',  'Resource9']].values  # 2,  2   47
events = [eventA, eventB, eventC, eventD, eventE, eventH, eventF, eventG, eventI]
            #0      1       2       3       4       5       6       7       8

continuous_conds = df.ix[:,['StartTime1',  'EndTime1', 'Cost1',
             'StartTime2',  'EndTime2', 'Cost2',
             'StartTime3',  'EndTime3', 'Cost3',
             'StartTime4',  'EndTime4', 'Cost4',
             'StartTime5',  'EndTime5', 'Cost5',
             'StartTime6',  'EndTime6', 'Cost6',
             'StartTime7',  'EndTime7', 'Cost7',
             'StartTime8',  'EndTime8', 'Cost8',
             'StartTime9',  'EndTime9', 'Cost9'
            ]].values

endtime11  = df['EndTime11'].values
endtime10 = df['EndTime10'].values
endtime = np.zeros((len1))

total_time = []

continuous_res = np.zeros([len1, 27])
for i in range(len1):
    for j in range(27):
        if type(continuous_conds[i, j]) == str:
                continuous_res[i, j] = int(continuous_conds[i, j].split(":")[0]) * 3600 + int(continuous_conds[i, j].split(":")[1]) * 60 + int(continuous_conds[i, j].split(":")[2])
        elif type(continuous_conds[i, j]) == int or type(continuous_conds[i, j]) == float:
            continuous_res[i, j] = continuous_conds[i, j]
        else:
            continuous_res[i, j] = continuous_conds[i, j].hour *  3600 + continuous_conds[i, j].minute * 60 + continuous_conds[i, j].second
    if type(endtime11[i]) == str:
        endtime[i] = int(endtime11[i].split(":")[0]) * 3600 + int(endtime11[i].split(":")[1]) * 60 + int(endtime11[i].split(":")[2])
    elif type(endtime10[i]) == str:
        endtime[i] = int(endtime10[i].split(":")[0]) * 3600 + int(endtime10[i].split(":")[1]) * 60 + int(endtime10[i].split(":")[2])
    elif endtime10[i] == 0:
        endtime[i] = endtime11[i].hour * 3600 + endtime11[i].minute * 60 + endtime11[i].second
    else:
        endtime[i] = endtime10[i].hour * 3600 + endtime10[i].minute * 60 + endtime10[i].second



# splitDataSet
event_ts = []
event_vs = []
for i in range(len(events)):
    tmp_event_ts, tmp_event_vs = splitDataSet(events[i], randomIndex)
    event_ts.append(tmp_event_ts)
    event_vs.append(tmp_event_vs)
    end_time_t, end_time_v = splitDataSet(endtime, randomIndex)
continuous_res_t, continuous_res_v = splitDataSet(continuous_res, randomIndex)

# encodeTime*100
event_tt = []
for k in range(100):
    event_tt.append(event_ts.copy())

#encode:
encodeTime = []
le = LabelEncoder()
oh = OneHotEncoder(sparse=False)
for i in range(len(event_ts)):
    start_time_tmp1 = time()
    for j in range(len(event_ts[i][0])):
        event_ts[i][:, j] = le.fit_transform(event_ts[i][:, j])
    oh.fit(event_ts[i])
    event_ts[i] = oh.transform(event_ts[i])
    end_time_tmp1 = time()
    encodeTime.append(end_time_tmp1 - start_time_tmp1)
print("encodeTime: ")
print(encodeTime)

encodeTime100times = []
for i in range(len(event_tt[0])):
    start_time_tmp2 = time()
    for k in range(len(event_tt)):
        for j in range(len(event_tt[k][i][0])):
            event_tt[k][i][:, j] = le.fit_transform(event_tt[k][i][:, j])
            oh.fit(event_tt[k][i])
            event_tt[k][i] = oh.transform(event_tt[k][i])
    end_time_tmp2 = time()
    encodeTime100times.append(end_time_tmp2 - start_time_tmp2)
print("encodeTime100times: ")
print(encodeTime100times)


for i in range(len(event_ts)):
    event_ts[i] =  np.hstack((event_ts[i], continuous_res_t[:, 3*i: 3*(i+1)]))

trainTime = []

tableA = event_ts[0]
for table in [tableA]:
    label = []
    for i in range(len(end_time_t)):
        label.append(end_time_t[i] - table[i, -2])
    start_time_A = time()
    X_train, X_test, y_train, y_test = train_test_split( table, label, random_state=0, test_size=.2 )
    modelA = XGBRegressor()
    modelA.fit(X_train, y_train)
    end_time_A = time()
    trainTime.append(end_time_A - start_time_A)
    y_pred = modelA.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableB = np.hstack((event_ts[0].copy(), event_ts[1].copy()))
for table in [tableB]:
    label = []
    for i in range(len(end_time_t)):
        label.append(end_time_t[i] - table[i, -2])
    start_time_B = time()
    X_train, X_test, y_train, y_test = train_test_split( table, label, random_state=0, test_size=.2 )
    modelB = XGBRegressor()
    modelB.fit(X_train, y_train)
    end_time_B = time()
    trainTime.append(end_time_B - start_time_B)
    y_pred = modelB.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableC = np.hstack((tableB.copy(), event_ts[2].copy()))
for table in [tableC]:
    label = []
    for i in range(len(end_time_t)):
        label.append(end_time_t[i] - table[i, -2])
    start_time_C = time()
    X_train, X_test, y_train, y_test = train_test_split( table, label, random_state=0, test_size=.2 )
    modelC = XGBRegressor()
    modelC.fit(X_train, y_train)
    end_time_C= time()
    trainTime.append(end_time_C - start_time_C)
    y_pred = modelC.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableD = np.hstack((tableC.copy(), event_ts[3].copy()))
tableD_1 = []
end_time_t_D = []
for i in range(len(tableD)):
    if tableD[i, -2] == 0:
        continue
    tableD_1.append(tableD[i])
    end_time_t_D.append(end_time_t[i] - tableD[i, -2])
tableD_1 = np.array(tableD_1)
end_time_t_D = np.array(end_time_t_D)
for table in [tableD_1]:
    start_time_D = time()
    X_train, X_test, y_train, y_test = train_test_split( table, end_time_t_D, random_state=0, test_size=.2 )
    modelD = XGBRegressor()
    modelD.fit(X_train, y_train)
    end_time_D = time()
    trainTime.append(end_time_D - start_time_D)
    y_pred = modelD.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableE = np.hstack((tableC.copy(), event_ts[4].copy()))
tableE_1 = []
end_time_t_E = []
for i in range(len(tableE)):
    if tableE[i, -2] == 0:
        continue
    tableE_1.append(tableE[i])
    end_time_t_E.append(end_time_t[i] - tableE[i, -2])
tableE_1 = np.array(tableE_1)
end_time_t_E = np.array(end_time_t_E)
for table in [tableE_1]:
    start_time_E = time()
    X_train, X_test, y_train, y_test = train_test_split( table, end_time_t_E, random_state=0, test_size=.2 )
    modelE = XGBRegressor()
    modelE.fit(X_train, y_train)
    end_time_E = time()
    trainTime.append(end_time_E - start_time_E)
    y_pred = modelE.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

# events = [eventA, eventB, eventC,  eventE, eventH, eventF, eventG, eventI]
            #0      1       2          4       5       6       7       8
      #cols: 5      4       2          7       7       7       7       4
      #  A:8  B:15 C:20 E:30 F:40(38) G:50(48) H(58)
tableH = np.hstack((tableE.copy(), event_ts[6].copy(), event_ts[7].copy(), event_ts[5].copy()))
tableH_1 = []
end_time_t_H = []
for i in range(len(tableH)):
    if tableH[i, -2] == 0:
        continue
    tableH_1.append(tableH[i])
    end_time_t_H.append(end_time_t[i] - tableH[i, -2])
    if tableH_1[-1][-2] < tableH_1[-1][38]:
        tableH_1[-1][37] = 0
        tableH_1[-1][38] = 0
        tableH_1[-1][39] = 0
    elif tableH_1[-1][-2] < tableH_1[-1][48]:
        tableH_1[-1][47] = 0
        tableH_1[-1][48] = 0
        tableH_1[-1][49] = 0
tableH_1 = np.array(tableH_1)
end_time_t_H = np.array(end_time_t_H)
for table in [tableH_1]:
    start_time_H = time()
    X_train, X_test, y_train, y_test = train_test_split( table, end_time_t_H, random_state=0, test_size=.2 )
    modelH = XGBRegressor()
    modelH.fit(X_train, y_train)
    end_time_H = time()
    trainTime.append(end_time_H - start_time_H)
    y_pred = modelH.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableF = np.hstack((tableE.copy(), event_ts[5].copy(), event_ts[6].copy()))
tableF_1 = []
end_time_t_F = []
for i in range(len(tableF)):
    if tableF[i, -2] == 0:
        continue
    tableF_1.append(tableF[i])
    end_time_t_F.append(end_time_t[i] - tableF[i, -2])
    if tableF_1[-1][-2] < tableF_1[-1][38]:
        tableF_1[-1][37] = 0
        tableF_1[-1][38] = 0
        tableF_1[-1][39] = 0
tableF_1 = np.array(tableF_1)
end_time_t_F = np.array(end_time_t_F)
for table in [tableF_1]:
    start_time_F = time()
    X_train, X_test, y_train, y_test = train_test_split( table, end_time_t_F, random_state=0, test_size=.2 )
    modelF = XGBRegressor()
    modelF.fit(X_train, y_train)
    end_time_F = time()
    trainTime.append(end_time_F - start_time_F)
    y_pred = modelF.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableG = np.hstack((tableE.copy(), event_ts[5].copy(), event_ts[7].copy()))
tableG_1 = []
end_time_t_G = []
for i in range(len(tableG)):
    if tableG[i, -2] == 0:
        continue
    tableG_1.append(tableG[i])
    end_time_t_G.append(end_time_t[i] - tableG[i, -2])
    if tableG_1[-1][-2] < tableG_1[-1][38]:
        tableG_1[-1][37] = 0
        tableG_1[-1][38] = 0
        tableG_1[-1][39] = 0
tableG_1 = np.array(tableG_1)
end_time_t_G = np.array(end_time_t_G)
for table in [tableG_1]:
    start_time_G = time()
    X_train, X_test, y_train, y_test = train_test_split( table, end_time_t_G, random_state=0, test_size=.2 )
    modelG = XGBRegressor()
    modelG.fit(X_train, y_train)
    end_time_G = time()
    trainTime.append(end_time_G - start_time_G)
    y_pred = modelG.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

tableI = np.hstack((tableC.copy(), event_ts[4].copy(), event_ts[5].copy(), event_ts[6].copy(), event_ts[7].copy(), event_ts[8].copy()))
tableI_1 = []
end_time_t_I = []
for i in range(len(tableI)):
    if tableI[i, -2] == 0:
        continue
    tableI_1.append(tableI[i])
    end_time_t_I.append(end_time_t[i] - tableI[i, -2])
tableI_1 = np.array(tableI_1)
end_time_t_I = np.array(end_time_t_I)
for table in [tableI_1]:
    start_time_I = time()
    X_train, X_test, y_train, y_test = train_test_split( table, end_time_t_I, random_state=0, test_size=.2 )
    modelI = XGBRegressor()
    modelI.fit(X_train, y_train)
    end_time_I = time()
    trainTime.append(end_time_I - start_time_I)
    y_pred = modelI.predict(X_test)
    mae = np.sum(np.abs(y_pred - y_test)) / (len(y_test) * 60.0)
    print("mae is : " + str(mae))

print(trainTime)

#vs_operations:
# one-hot encode
# 线下encode时间*1000
event_vv = []
for i in range(1000):
    event_vv.append(event_vs.copy())

encodeTimev2 = []
for i in range(len(event_vv[0])):
    start_time_tmpv2 = time()
    for k in range(len(event_vv)):
        for j in range(len(event_vv[k][i][0])):
            event_vv[k][i][:, j] = le.fit_transform(event_vv[k][i][:, j])
        oh.fit(event_vv[k][i])
        event_vv[k][i] = oh.transform(event_vv[k][i])
    end_time_tmpv2 = time()
    encodeTimev2.append(end_time_tmpv2 - start_time_tmpv2)
print("线上encode时间*1000:")
print(encodeTimev2)

encodeTimev = []
for i in range(len(event_vs)):
    start_time_tmpv = time()
    for j in range(len(event_vs[i][0])):
        event_vs[i][:, j] = le.fit_transform(event_vs[i][:, j])
    oh.fit(event_vs[i])
    event_vs[i] = oh.transform(event_vs[i])
    end_time_tmpv = time()
    encodeTimev.append(end_time_tmpv - start_time_tmpv)
print("encodeTimev:")
print(encodeTimev)
# 拼接
for i in range(len(event_vs)):
    event_vs[i] =  np.hstack((event_vs[i], continuous_res_v[:, 3*i: 3*(i+1)]))

cnt = 100

process_time = []
tableAA = event_vs[0]
start_time_AA = time()
for i in range(cnt):
    A_pred = modelA.predict(tableAA)
end_time_AA = time()
process_time.append(end_time_AA - start_time_AA)


tableBB = np.hstack((event_vs[0].copy(), event_vs[1].copy()))
start_time_BB = time()
for i in range(cnt):
    B_pred = modelB.predict(tableBB)
end_time_BB = time()
process_time.append(end_time_BB - start_time_BB)


tableCC = np.hstack((tableBB.copy(), event_vs[2].copy()))
start_time_CC = time()
for i in range(cnt):
    C_pred = modelC.predict(tableCC)
end_time_CC = time()
process_time.append(end_time_CC - start_time_CC)

tableDD = np.hstack((tableCC.copy(), event_vs[3].copy()))
tableDD_1 = []
end_time_v_DD = []
for i in range(len(tableDD)):
    if tableDD[i, -2] == 0:
        continue
    tableDD_1.append(tableDD[i])
    end_time_v_DD.append(end_time_v[i] - tableDD[i, -2])
tableDD_1 = np.array(tableDD_1)
end_time_v_DD = np.array(end_time_v_DD)
start_time_DD = time()
for i in range(cnt):
    D_pred = modelD.predict(tableDD_1)
end_time_DD = time()
process_time.append(end_time_DD - start_time_DD)

tableEE = np.hstack((tableCC.copy(), event_vs[4].copy()))
tableEE_1 = []
end_time_v_EE = []
for i in range(len(tableEE)):
    if tableEE[i, -2] == 0:
        continue
    tableEE_1.append(tableEE[i])
    end_time_v_EE.append(end_time_v[i] - tableEE[i, -2])
tableEE_1 = np.array(tableEE_1)
end_time_v_EE = np.array(end_time_v_EE)
start_time_EE = time()
for i in range(cnt):
    E_pred = modelE.predict(tableEE_1)
end_time_EE = time()
process_time.append(end_time_EE - start_time_EE)

tableHH = np.hstack((tableEE.copy(), event_vs[6].copy(), event_vs[7].copy(), event_vs[5].copy()))
tableHH_1 = []
end_time_v_HH = []
for i in range(len(tableHH)):
    if tableHH[i, -2] == 0:
        continue
    tableHH_1.append(tableHH[i])
    end_time_v_HH.append(end_time_v[i] - tableHH[i, -2])
    if tableHH_1[-1][-2] < tableHH_1[-1][38]:
        tableHH_1[-1][37] = 0
        tableHH_1[-1][38] = 0
        tableHH_1[-1][39] = 0
    elif tableHH_1[-1][-2] < tableHH_1[-1][48]:
        tableHH_1[-1][47] = 0
        tableHH_1[-1][48] = 0
        tableHH_1[-1][49] = 0
tableHH_1 = np.array(tableHH_1)
end_time_v_HH = np.array(end_time_v_HH)
start_time_HH = time()
for i in range(cnt):
    H_pred = modelH.predict(tableHH_1)
end_time_HH = time()
process_time.append(end_time_HH - start_time_HH)

tableFF = np.hstack((tableEE.copy(), event_vs[5].copy(), event_vs[6].copy()))
tableFF_1 = []
end_time_v_FF = []
for i in range(len(tableFF)):
    if tableFF[i, -2] == 0:
        continue
    tableFF_1.append(tableFF[i])
    end_time_v_FF.append(end_time_v[i] - tableFF[i, -2])
    if tableFF_1[-1][-2] < tableFF_1[-1][38]:
        tableFF_1[-1][37] = 0
        tableFF_1[-1][38] = 0
        tableFF_1[-1][39] = 0
tableFF_1 = np.array(tableFF_1)
end_time_v_FF = np.array(end_time_v_FF)
start_time_FF = time()
for i in range(cnt):
    F_pred = modelF.predict(tableFF_1)
end_time_FF = time()
process_time.append(end_time_FF - start_time_FF)

tableGG = np.hstack((tableEE.copy(), event_vs[5].copy(), event_vs[7].copy()))
tableGG_1 = []
end_time_v_GG = []
for i in range(len(tableGG)):
    if tableGG[i, -2] == 0:
        continue
    tableGG_1.append(tableGG[i])
    end_time_v_GG.append(end_time_v[i] - tableGG[i, -2])
    if tableGG_1[-1][-2] < tableGG_1[-1][38]:
        tableGG_1[-1][37] = 0
        tableGG_1[-1][38] = 0
        tableGG_1[-1][39] = 0
tableGG_1 = np.array(tableGG_1)
end_time_v_GG = np.array(end_time_v_GG)
start_time_GG = time()
for i in range(cnt):
    G_pred = modelG.predict(tableGG_1)
end_time_GG = time()
process_time.append(end_time_GG - start_time_GG)

tableII = np.hstack((tableCC.copy(), event_vs[4].copy(), event_vs[5].copy(), event_vs[6].copy(), event_vs[7].copy(), event_vs[8].copy()))
tableII_1 = []
end_time_v_II = []
for i in range(len(tableII)):
    if tableII[i, -2] == 0:
        continue
    tableII_1.append(tableII[i])
    end_time_v_II.append(end_time_v[i] - tableII[i, -2])
tableII_1 = np.array(tableII_1)
end_time_v_II = np.array(end_time_v_II)
start_time_II = time()
for i in range(cnt):
    I_pred = modelI.predict(tableII_1)
end_time_II = time()
process_time.append(end_time_II - start_time_II)
print("process_time:")
print(process_time)

